package ModelLayer;

public class Session
{
    private boolean loggedIn;
    private int sessionId;
    private int personId;
    private String personPassword;
    private int accessLevel;
    private boolean active;

    public Session(int sessionId){
        this.sessionId = sessionId;
        this.active = true;
        this.loggedIn = false;
    }

    public boolean login(int id, String password){
        if(ManagerContainer.getInstance().findManagerById(id) !=null &&
        password.equals( ManagerContainer.getInstance().findManagerById(id).getPassword())){
            setPersonId(id);
            setPersonPassword(password);
            setLoggedIn(true);
            setAccessLevel(2);
            return true;
        }
        if( EmployeeContainer.getInstance().findEmployeeById(id) != null &&
        password.equals(EmployeeContainer.getInstance().findEmployeeById(id).getPassword())){
            setPersonId(id);
            setPersonPassword(password);
            setLoggedIn(true);
            setAccessLevel(1);
            return true;
        }else{
            setAccessLevel(0);
            return false;
        }
    }

    public void logOut(){
        loggedIn = false;
        setPersonId(0);
        setPersonPassword("");
        setAccessLevel(0);
        setActive(false);
    }

    public int getSessionId() {
        return sessionId;
    }

    public void setSessionId(int sessionId) {
        this.sessionId = sessionId;
    }

    public String getPersonPassword() {
        return personPassword;
    }

    public void setPersonPassword(String personPassword) {
        this.personPassword = personPassword;
    }

    public int getPersonId() {
        return personId;
    }

    public void setPersonId(int personId) {
        this.personId = personId;
    }

    public boolean isLoggedIn(){
        return loggedIn;
    }

    public void setLoggedIn(boolean loggedIn) {
        this.loggedIn = loggedIn;
    }

    public int getAccessLevel() {
        return accessLevel;
    }

    public void setAccessLevel(int accessLevel) {
        this.accessLevel = accessLevel;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
}
